/**
 * Created by Administrator on 2017/3/1 0001.
 */
var resource;
var mode;
var pixiStageW=740;
var pixiStageH=1136;
var pixiStage=new PIXI.Stage(0xFF0000);
var ratio=1;
var canvas;
var PixiMain={

    create:function () {
        // ratio=window.devicePixelRatio;
        // var cc=document.getElementById('div_2d');
        // console.log(cc);
        // var context=cc.getContext('2d')
        // var devicePixelRatio = window.devicePixelRatio || 1;
        //  var  backingStoreRatio = context.webkitBackingStorePixelRatio ||
        //         context.mozBackingStorePixelRatio ||
        //         context.msBackingStorePixelRatio ||
        //         context.oBackingStorePixelRatio ||
        //         context.backingStorePixelRatio || 1,
        //
        //     ratio = devicePixelRatio / backingStoreRatio;

        var pixi_renderer=PIXI.autoDetectRenderer(pixiStageW,pixiStageH,{antialias:true,transparent:true,resolution:ratio});
        canvas=pixi_renderer.view;
        var div_pixi=document.getElementById('div_2d');

        div_pixi.appendChild(pixi_renderer.view);

        var preload=Preload.create();
        preload.init(pixiStage,pixiStageW,pixiStageH);
        var con_whole=new PIXI.Container();
        pixiStage.addChild(con_whole);

        document.addEventListener('Main_LoadComplete',gameStart);
        function gameStart(e) {
            resource=e.detail.resources;
            // var game=Game.create();
            // pixiStage.addChildAt(game.ui,0);
            // pixi_renderer.render(pixiStage);

            document.getElementById('div_3d').style.zIndex=100;
            threeIn();
        }

        resize();
        window.onresize = resizeHandlerPIXI;
        function resizeHandlerPIXI() {
            setTimeout(function () {
                 resize();
            },200)
        };
        function resize()
        {
            // canvas.width = window.innerWidth * ratio;
            // canvas.height = window.innerHeight * ratio;
            // canvas.style.width = window.innerWidth + 'px';
            // canvas.style.height = window.innerHeight + 'px';
            pixi_renderer.resize(window.innerWidth*ratio, window.innerHeight*ratio);
                mode='noBorder';
                switch (mode) {
                    case 'exactFit':
                        pixiStage.scale.x = window.innerWidth / pixiStageW;
                        pixiStage.scale.y = window.innerHeight / pixiStageH;
                        break;
                    case 'noBorder':
                        pixiStage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerWidth / pixiStageW)*ratio : (window.innerHeight / pixiStageH)*ratio;
                        pixiStage.scale.y = pixiStage.scale.x;
                        break;
                    case 'noScale':
                        pixiStage.scale.x = 1;
                        pixiStage.scale.y = 1;
                        break;
                    case 'showAll':
                        pixiStage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerHeight / pixiStageH) : (window.innerWidth / pixiStageW);
                        pixiStage.scale.y = pixiStage.scale.x;
                        break;
                }
                pixiStage.x = (window.innerWidth*ratio - pixiStageW * pixiStage.scale.x) * .5;
                pixiStage.y = (window.innerHeight*ratio - pixiStageH * pixiStage.scale.y) * .5;

        }

        // var globalID;
        // globalID=
        requestAnimationFrame(animate);
        // cancelAnimationFrame(globalID);
        function animate() {
            requestAnimationFrame(animate);
            pixi_renderer.render(pixiStage);
        }
    }
}